Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure we handle the scenario the payment service code expects there to be an active span but finds none #2129

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

keyoke
Copy link
Contributor

@keyoke keyoke commented Mar 20, 2025

I am proposing a very minor change to handle when auto-instrumentation is disabled( similar to #2124 ) for the payment service. In this scenario, an exception is raised but I would expect it to be handled gracefully.

Changes

Added some very simple logic to check if the current active span is undefined, if it is we create a new span & mark this as the active span.

Merge Requirements

For new features contributions, please make sure you have completed the following
essential items:

  • CHANGELOG.md updated to document new feature additions
  • Appropriate documentation updates in the docs
  • Appropriate Helm chart updates in the helm-charts

Maintainers will not merge until the above have been completed. If you're unsure
which docs need to be changed ping the
@open-telemetry/demo-approvers.

@keyoke keyoke requested a review from a team as a code owner March 20, 2025 17:33
Copy link

linux-foundation-easycla bot commented Mar 20, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

@keyoke keyoke changed the title Ensure we handle the scenario the payment service code expects there to be an active span Ensure we handle the scenario the payment service code expects there to be an active span but finds none Mar 20, 2025
@julianocosta89
Copy link
Member

@pichlermarc I would love to hear your opinion here

@puckpuck
Copy link
Contributor

I understand if the SDK is disabled, the service should not throw an error which is what #2124 discusses.

I struggle to understand in what scenario we need to start a trace if one does not exists.

Copy link
Member

@pichlermarc pichlermarc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I struggle to understand in what scenario we need to start a trace if one does not exists.

I agree - in my opinion the way to address the problem of the crashing app would be either to:

  • optional chain on the span object obtained via getActiveSpan() wherever it's used
    • example: span.setAttributes({...}) -> span?.setAttributes({...})
  • create and end an internal span always no matter if a trace was already started or not to which you can attach any attributes and errors you like, while retaining semantics for the grpc span that's likely being modified here (since that one is strictly supposed to follow the gRPC semconv anyway and modifying error status may interfere with that).

@@ -4,12 +4,22 @@ const grpc = require('@grpc/grpc-js')
const protoLoader = require('@grpc/proto-loader')
const health = require('grpc-js-health-check')
const opentelemetry = require('@opentelemetry/api')
const tracer = opentelemetry.trace.getTracer(process.env.OTEL_SERVICE_NAME);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.env.OTEL_SERVICE_NAME may be undefined, which is not a valid name for the tracer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok thanks understood. I have switched to optional chain as suggested above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I guess I misundertood a little - Should we create the internal span? I think this makes more sense as we retain the original semantics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants